@extends('admin.layout.main')
@section('content')
    <style type="text/css">
      .left-filter{margin-left:8px;}
    </style>
    <link rel="stylesheet" href="{{asset('/adminlte/plugins/iCheck/all.css')}}">
    <section class="content-header">
      <h1>
        新增用户
      </h1>
      <ol class="breadcrumb">
        <li><a href="javascript:void(0)"><i class="fa fa-dashboard"></i> 游戏用户</a></li>
        <li class="active">日新增用户</li>
      </ol>
    </section>
    <section class="content">
        <!-- Small boxes (Stat box) -->
        <div class="row">
            <div class="col-lg-12 col-xs-6">
                <div class="box">
                    <div class="box-header with-border">
                        <div class="row">
                        </div> 
                    </div>
                    
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover" id="user-list">
                            <div class="dataTables_filter">
                                <form action="/admin/users_new/index" method="GET">
                                    <button type="submit" class="btn btn-info btn-sm">查询:</button><input type="search" placeholder="请输入关键字" name="keywords" class="form-control input-sm" value="{{$keywords}}">
                                      <button style="height:30px;line-height:18px" type="button" class="btn btn-default" id="daterange-btn">
                                        <span>
                                          <i class="fa fa-calendar"></i>
                                        </span>
                                        <i class="fa fa-caret-down"></i>
                                      </button>
                                    
                                    <input type="hidden" name="time">
                                </form>
                            </div>
                            <thead>
                                <tr>
                                    <th>用户id</th>
                                    <th>用户昵称</th>
                                    <th>绑定代理</th>
                                    <th>注册时间</th>
                                    <th>房卡数量</th>
                                    <th>累计消费</th>
                                    <th>累计局数</th>
                                    <th>操作</th>
                                </tr>
                            </thead>    
                            <tbody> 
                                @foreach($users as $user)
                                    <tr id="{{$user->id}}">
                                        <td>{{$user->userid}}</td>
                                        <td>
                                          @if($user->headimg)
                                            <img src="{{$user->headimg}}" style="width:16px">
                                          @endif
                                          @if($user->nickname) 
                                            {{$user->nickname}} 
                                          @else 
                                            {{base64_decode($user->name)}} 
                                          @endif
                                        </td>
                                        <td>
                                          @if($user->userAgent)
                                            @if($user->userAgent->avatar)
                                              <img src="{{$user->userAgent->avatar}}" style="width:16px">
                                            @endif
                                            @if($user->userAgent->realname)
                                              {{$user->userAgent->realname}}
                                            @endif
                                            <br>
                                            ID：{{$user->userAgent->id}}
                                          @else
                                            未绑定
                                          @endif
                                        </td>
                                        <td>{{$user->created_at}}</td>
                                        <td>{{$user->gems}}</td>
                                        <td>{{$user->totalCost()}}</td>
                                        <td>{{$user->totalGames()}}</td>
                                        <td>
                                          <a href="javascript:void(0)" class="view-user"><i class="fa fa-fw fa-eye"></i>用户详情</a>
                                          <a href="/admin/users_new/cost_record/{{$user->id}}" class="view-money"><i class="fa fa-fw fa-jpy"></i>消费记录</a>
                                          <a href="/admin/users_new/game_record/{{$user->id}}" class="view-game"><i class="fa fa-fw fa-gamepad"></i>游戏记录</a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                        {{$users->links()}}
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- datepicker -->
    <script src="{{asset('/adminlte/plugins/datepicker/bootstrap-datepicker.js')}}"></script>
    <!-- iCheck 1.0.1 -->
    <script src="{{asset('/adminlte/plugins/iCheck/icheck.min.js')}}"></script>
    <script type="text/javascript">
        // $(function () {
        //     $('#user-list').DataTable({
        //       "paging": false,
        //       "lengthChange": false,
        //       "searching": false,
        //       "info": false,
        //       "autoWidth": true,
        //       "columns": [
        //         {"orderable": false},
        //         {"orderable": false},
        //         {"orderable": false},
        //         {"orderable": false},
        //         {"orderable": false},
        //         {"orderable": false},
        //         {"orderable": false},
        //         {"orderable": false}
        //       ]
        //     });
        // });

        $(function () {
            //Date range as a button
            $('#daterange-btn').daterangepicker(
                {
                  ranges: {
                    '今天': [moment(), moment().add(1, 'days')],
                    '昨天': [moment().subtract(1, 'days'), moment()],
                    '最近7天': [moment().subtract(6, 'days'), moment().add(1, 'days')],
                    '最近30天': [moment().subtract(29, 'days'), moment().add(1, 'days')],
                    '本月': [moment().startOf('month'), moment().endOf('month')],
                    '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                  },
                  startDate: moment().subtract(29, 'days'),
                  endDate: moment()
                },
                function (start, end) {
                  $('#daterange-btn span').html(start.format('YYYY-MM-DD') + ' ~ ' + end.format('YYYY-MM-DD'));
                  $("input[name = time]").val(start.format('YYYY-MM-DD') + ' ~ ' + end.format('YYYY-MM-DD'));
                }
            );
        });

        $('.all_check').click(function(){
            $('.checkbox_member').click();
        });

        $('#datepicker').datepicker({
          autoclose: true,
          endDate: new Date()
        });

        $('.view-user').click(function(){
          var u_id = $(this).parents('tr').attr('id');
          dialog_group('/admin/users_new/view/'+u_id, '用户详情');
        });
    </script>
@endsection